<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop" ref="buttondiv">
          <table style="width: 100%">
              <tr>
                  <td width="60" style="text-align: right">条形码</td>
                  <td width="200">
                      <el-input v-model="barcode" @keyup.enter.native="ChangeBarcode" autofocus @focus="barcodeFocus"
                          ref="barcode"></el-input>
                  </td>
                  <td width="20"></td>
                  <td width="140">姓名：{{ patname }}</td>
                  <td width="80">性别：{{ patsex }}</td>
                  <td width="100">年龄：{{ patage }}</td>
                  <td width="140">今日采集病人数：{{ patnum }}</td>
                  <td width="140">今日采集标本数：{{ barnum }}</td>
                  <td>
                      <el-button @click="gotoDetail" size="mini" icon="el-icon-search"></el-button>
                  </td>
                  <td style="text-align: right">
                      <table>
                          <tr>
                              <td width="1000px"></td>
                              <td v-for="buttonsortdef in buttonsortdeflist" :key="buttonsortdef">
                                  <el-button v-if="buttonsortdef == 'SAVE'" @click="submitreq()">采样确认</el-button>
                                  <el-button v-else-if="buttonsortdef == 'PRINTBACK'" @click="btnRePrint_click()">打印回单
                                  </el-button>
                                  <el-button v-else-if="buttonsortdef == 'PRINTBARCODE'" @click="ChangeBarcode()">重打条码
                                  </el-button>
                                  <el-button v-else-if="buttonsortdef == 'PHOTO'">拍照</el-button>
                                  <el-button v-else-if="buttonsortdef == 'VIEWPHOTO'">查看照片</el-button>
                                  <el-button v-else-if="buttonsortdef == 'VIEWPRE'" @click="querypredt()">查看预出报告时间
                                  </el-button>
                                  <el-button v-else-if="buttonsortdef == 'UNCOLLECT'" @click="Cancel()">取消采样
                                  </el-button>
                              </td>
                          </tr>
                      </table>
                  </td>
              </tr>
          </table>
      </div>
      <div class="pagecenter">
          <rm-layout-right :fixsize="520" :splitwidth="5" :minfixsize="200" :maxflxsize="2000">
              <div class="middle-center" ref="xTableDiv" style="height: 100%">
                  <div style="height: 50%; width: 100%">
                      <vxe-table :data="tableData" :loading="loading" :keyboard-config="keyConfig"
                          :keyboard-local-config="keyLocalConfig" @cell-dblclick="cellDBLClickEvent"
                          :select-config="selectConfig" :sort-config="{ trigger: 'cell' }"
                          :cell-class-name="cellClassName" :row-class-name="rowClassName"
                          @current-change="currentChangeEvent" border fit height="auto" header-align="center"
                          highlight-current-row highlight-hover-column ref="xTable" resizable
                          show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                          <vxe-table-column :key="item.field" :field="item.field" :title="item.title"
                              :width="item.width" v-for="item in tableColumn"></vxe-table-column>
                          <template v-slot:fix>
                              <div
                                  style="font-size:20px; padding-left: 10px; height:32px; color:red; float: left; text-align: left; vertical-align:bottom; font-weight: bold; width: 45%">
                                  共 {{ tableData.length }} 条</div>
                              <div v-show="isnotclearsamplelist == '1'"
                                  style="font-size: 17px; float: right; padding: 3px; background-color: #fff; text-align: right; font-weight: bold; width: 45%">
                                  <el-button @click="btnclearlist()" class="el-button--310">清空</el-button>
                              </div>
                          </template>
                      </vxe-table>
                  </div>
                  <div style="height: 49%; width: 100%; margin-top: 5px">
                      <vxe-table :data="tableDataAll" :loading="loading" :keyboard-config="keyConfig"
                          :keyboard-local-config="keyLocalConfig" @cell-dblclick="cellDBLClickEvent"
                          :select-config="selectConfig" :sort-config="{ trigger: 'cell' }"
                          @current-change="currentChangeEvent" border fit height="auto" header-align="center"
                          highlight-current-row highlight-hover-column ref="xTable1" resizable
                          show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                          <vxe-table-column :key="item.field" :field="item.field" :title="item.title"
                              :width="item.width" v-for="item in tableColumn"></vxe-table-column>
                      </vxe-table>
                  </div>
              </div>
              <template v-slot:fix>
                  <div class="middle-right">
                      <div ref="xTableDiv1" style="height: 100%">
                          <vxe-table :data.sync="tableDataDetail" :select-config="selectConfig" height="auto"
                              :sort-config="{ trigger: 'cell' }" :loading="loadingDetail" highlight-current-row
                              highlight-hover-row border fit highlight-hover-column resizable header-align="center"
                              show-header-overflow="tooltip" show-overflow="tooltip" ref="xTable2" size="mini" stripe>
                              <vxe-table-column :key="item.field" :field="item.field" :title="item.title"
                                  :width="item.width" v-for="item in tableColumnDetail"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </div>
              </template>
          </rm-layout-right>
      </div>
      <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="提示" :visible.sync="CancelVisible" width="30%">
          <div class="el-message-box__status el-icon-warning"></div>
          <div class="el-message-box__message" style="padding-top: 24px">
              <p>你确定要对此申请取消采样吗?</p>
              <p>病人姓名：{{ reqmaster.pat_name }}</p>
              <p>条码号：{{ reqmaster.barcode }}</p>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button @click="CancelCommit()">确 定</el-button>
              <el-button @click="CancelVisible = false">取 消</el-button>
          </span>
      </el-dialog>

      <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="查看预出报告时间" :visible.sync="PredtVisible"
          width="800px">
          <div ref="xTableDiv1" style="height: 500px">
              <vxe-table :data.sync="tableDataPre" :select-config="selectConfig" height="auto"
                  :sort-config="{ trigger: 'cell' }" highlight-current-row highlight-hover-row border fit
                  highlight-hover-column resizable header-align="center" show-header-overflow="tooltip"
                  show-overflow="tooltip" ref="xTable3" size="mini" stripe>
                  <vxe-table-column field="barcode" title="条码号" width="100"></vxe-table-column>
                  <vxe-table-column field="sample_items" title="项目描述" width="140"></vxe-table-column>
                  <vxe-table-column field="prereport_dt" title="预出报告时间" width="140"></vxe-table-column>
                  <vxe-table-column field="specimen_name" title="标本类型" width="80"></vxe-table-column>
                  <vxe-table-column field="sampled_dt" title="采样时间" width="120"></vxe-table-column>
                  <vxe-table-column field="sampled_username" title="采样用户" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_no" title="病人号" width="80"></vxe-table-column>
                  <vxe-table-column field="inp_date" title="入院日期" width="80"></vxe-table-column>
                  <vxe-table-column field="pat_name" title="病人姓名" width="80"></vxe-table-column>
                  <vxe-table-column field="pat_sexname" title="性别" width="80"></vxe-table-column>
                  <vxe-table-column field="pat_birth" title="病人生日" width="80"></vxe-table-column>
                  <vxe-table-column field="pat_ageyear" title="年龄岁数" width="80"></vxe-table-column>
                  <vxe-table-column field="pat_typename" title="病人类型" width="80"></vxe-table-column>
              </vxe-table>
          </div>
      </el-dialog>
      <!-- 附加报告输入弹窗 -->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请输入附加报告项目结果" :visible.sync="addRptItemVisible" width="550px" min-height="300px">
          <vxe-table show-overflow="tooltip" :data="AddaRptItemList" border height="auto" ref="AddaRptItemTable" resizable size="mini" stripe :edit-config="{ trigger: 'click', mode: 'cell' }">
              <vxe-table-column field="barcode" title="条码号" width="120" header-align="center"></vxe-table-column>
              <vxe-table-column field="rpt_itemname" title="项目名称" width="200" header-align="center"></vxe-table-column>
              <vxe-table-column field="val" title="项目结果" width="120" header-align="center" :edit-render="{ name: 'input' }"></vxe-table-column>
              <vxe-table-column field="unit" title="单位" width="60" header-align="center"></vxe-table-column>
          </vxe-table>
          <span slot="footer" class="dialog-footer">
              <el-button @click="CommitTips()">确 定</el-button>
              <el-button @click="CancelTips()">取 消</el-button>
          </span>
      </el-dialog>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
export default {
  name: "REQ111",
  data() {
      return {
          patname: "",
          patsex: "",
          patage: "",
          barcode: "",
          patnum: "",
          barnum: "",

          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          keyLocalConfig: {
              isArrow: true,
          },
          selectConfig: { tigger: "row" },
          loading: false,
          loadingDetail: false,
          tableData: [],
          tableDataAll: [],
          tableDataDetail: [],
          tableColumn: [],
          tableColumnDetail: [],
          Options: [],

          CancelVisible: false,
          reqmaster: {},
          reqitem: "",
          patno: "",
          UpPatno: "",

          //查看预出报告时间弹窗
          PredtVisible: false,
          tableDataPre: [],
          // 切换病人时不清空已确认列表
          isnotclearsamplelist: "",
          // 单个扫描试管条码也要最后点击采样确认按钮再存盘
          MUSTCLICKEDSAMPLED: "",
          //按钮排序
          buttonsortdeflist: [],
          addRptItemVisible: false,
          AddaRptItemList: [],

      };
  },
  created() {
      this.InitPageData();
  },

  activated() {
      this.barcode = "";
      this.$refs.barcode.focus();
  },
  mounted() { },
  updated() { },
  methods: {
      barcodeFocus() {
          this.$refs.barcode.select();
      },
      gotoDetail() {
          this.$router.push({
              path: "/REQ141",
              query: {
                  istoday: true,
                  userinfoval: this.$tool.getSession(this.$tool.loginuserno),
              },
          });
      },
      currentChangeEvent({ row }) {
          this.reqmaster = row;
          this.FindDetail();
      },
      InitPageData() {
          this.FindAll();
          this.FindDetail();
          this.InitOption();
      },
      InitOption() {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "InitOption",
                  },
              })
              .then((res) => {
                  if (res && res.errcode == "1") {
                      this.Options = res;
                      this.barnum = res.barnum;
                      this.patnum = res.patnum;
                      this.MUSTCLICKEDSAMPLED = res.MUSTCLICKEDSAMPLED;
                      this.isnotclearsamplelist = res.isnotclearsamplelist;
                      this.buttonsortdeflist = res.buttonsortdef.split(",");
                  }
              });
      },
      FindAll() {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "query",
                      barcode: this.barcode,
                      patnos: this.UpPatno,
                  },
              })
              .then((res) => {
                  this.tableColumn = res.Cols;
                  if (res.errcode == "1") {
                      //病人号如果无数据，下方表格为空
                      if (res.Patno == "" || res.Patno == null || res.Patno == undefined) {
                          this.tableDataAll = [];
                      }
                      if (res.Data2 != null && res.Data2.length > 0) {
                          this.tableDataAll = res.Data2;

                          var temprow = res.Data2[0];
                          if (this.patno == res.Patno && res.Patno != "") {
                              this.sampling(res);
                          } else {
                              this.sampling_patno(res);
                          }
                          this.patno = res.Patno;
                          this.patname = temprow.pat_name;
                          this.patsex = temprow.pat_sex == 1 ? "男" : "女";
                          this.patage = temprow.pat_agestr;
                      }
                  } else {
                      this.$nextTick(() => {
                          this.barcodeFocus();
                      });
                      this.barcode = res.errmsg;
                  }
                  this.loading = false;
              });
      },
      sampling(res) {
          if (res.Data2.length > 0 || res.isC == "1") {
              if (res.errcode == "1") {
                  if (this.tableData.length > 0) {
                      for (let index = 0; index < this.tableData.length; index++) {
                          //新添加时，先把原先的状态设置为0
                          this.tableData[index].isC = 0;
                      }
                  }
                  var barcodeArr = res.Barcode.split(',');
                  for (let index = 0; index < barcodeArr.length; index++) {
                      const element = barcodeArr[index];
                      var row = this.tableDataAll.filter((item) => item.barcode == element);
                      var rowidnex = this.tableDataAll.findIndex(function (data) {
                          return data.barcode == element;
                      });
                      if (res.Master != "" && res.Master != null && res.Master != undefined) {
                          console.log(res)
                          row[0].req_statname = res.Master.req_statname;
                          row[0].req_stat = res.Master.req_stat;
                          row[0].sampled_dt = res.Master.sampled_dt;
                          row[0].sampled_user = res.Master.sampled_user;
                          row[0].sampled_username = res.Master.sampled_username;
                      }
                      if (res.isC != "1") {
                          //不是回单条码号
                          this.tableData.splice(0, 0, row[0]);
                          this.$refs.xTable.insertAt(row[0], -1);
                      }
                      if (this.tableDataAll.length > 0) {
                          this.tableDataAll.splice(rowidnex, 1);
                          this.$refs.xTable1.remove(row[0]);
                      }
                  }
                  if (res.isC == "1" && res.Data1 != undefined && res.Data1 != null && res.Data1 != "") {
                      if (res.Data1.length > 0) {
                          for (let index = 0; index < res.Data1.length; index++) {
                              const element = res.Data1[index];
                              element.isC = 1;
                              this.tableData.splice(0, 0, element);
                              this.$refs.xTable.insertAt(element, -1);
                          }
                      }
                  }
                  if (res.reinfo) {
                      if (res.reinfo.Item1 == "1") {
                          this.barcode = this.barcode + " 采样确认成功";
                          if (res.issave) {
                              this.patnum = res.patnum;
                              this.barnum = res.barnum;
                          }
                          this.reqmaster = this.tableData[0];
                          this.FindDetail();
                          if(this.MUSTCLICKEDSAMPLED != '1'){
                              //采样确认成功,查询是否有附加报告
                              this.getAddRptItem(res.Barcode)
                                  .then((res) => {
                                      if (!!res.data && res.data.length > 0) {
                                          this.addRptItemVisible = true;
                                          this.AddaRptItemList = res.data;
                                      }
                                  });
                          }
                      } else if (res.reinfo.Item2 != "") {
                          this.barcode = this.barcode + " " + res.reinfo.Item2;
                      }
                  }
                  this.UpPatno += "," + res.Barcode;
                  if (this.Options.sampledprintbarcode == "1") this.$pub.printbarcode(this, this.tableData[0], "1", this.Options.lisbarstyle, "", "1");

                  this.$refs.xTable.setCurrentRow(this.tableData[0]);
                  this.$nextTick(() => {
                      this.$refs.barcode.select();
                  });
              } else {
                  this.UpPatno = "";
                  this.barcode = res.errmsg;
                  this.$nextTick(() => {
                      this.barcodeFocus();
                  });
              }
          }
      },
      sampling_patno(res) {
          this.UpPatno = "";
          if (res.Data2.length > 0 || res.isC == "1") {
              if (res.errcode == "1") {
                  if (this.isnotclearsamplelist != "1") {
                      //切换病人时清空已确认列表
                      this.tableData = [];
                  }
                  if (this.tableData.length > 0) {
                      for (let index = 0; index < this.tableData.length; index++) {
                          //新添加回单条码时，先把原先的状态设置为0
                          this.tableData[index].isC = 0;
                      }
                  }
                  var barcodeArr = res.Barcode.split(',');
                  for (let index = 0; index < barcodeArr.length; index++) {
                      const element = barcodeArr[index];
                      var row = this.tableDataAll.filter((item) => item.barcode == element);

                      var rowidnex = this.tableDataAll.findIndex(function (data) {
                          return data.barcode == element;
                      });

                      if (res.Master != "" && res.Master != null && res.Master != undefined) {
                          row[0].req_statname = res.Master.req_statname;
                          row[0].req_stat = res.Master.req_stat;
                          row[0].sampled_dt = res.Master.sampled_dt;
                          row[0].sampled_user = res.Master.sampled_user;
                          row[0].sampled_username = res.Master.sampled_username;
                      }
                      if (res.isC != "1") {
                          //不是回单条码号
                          this.tableData.splice(0, 0, row[0]);
                          this.$refs.xTable.insertAt(row[0], -1);
                      }
                      if (this.tableDataAll.length > 0) {
                          this.tableDataAll.splice(rowidnex, 1);
                          this.$refs.xTable1.remove(row[0]);
                      }
                  }
                  if (res.isC == "1" && res.Data1 != undefined && res.Data1 != null && res.Data1 != "") {
                      if (res.Data1.length > 0) {
                          for (let index = 0; index < res.Data1.length; index++) {
                              const element = res.Data1[index];
                              element.isC = 1;
                              this.tableData.splice(0, 0, element);
                              this.$refs.xTable.insertAt(element, -1);
                          }
                      }
                  }
                  this.UpPatno = res.Barcode;
                  if (res.reinfo) {
                      if (res.reinfo.Item1 == "1") {
                          this.barcode = this.barcode + " 采样确认成功";
                          this.reqmaster = this.tableData[0];
                          this.FindDetail();
                          if (res.issave) {
                              this.patnum = res.patnum;
                              this.barnum = res.barnum;
                          }
                          if(this.MUSTCLICKEDSAMPLED != '1'){
                              //采样确认成功,查询是否有附加报告
                              this.getAddRptItem(res.Barcode)
                                  .then((res) => {
                                      if (!!res.data && res.data.length > 0) {
                                          this.addRptItemVisible = true;
                                          this.AddaRptItemList = res.data;
                                      }
                                  });
                          }
                      } else if (res.reinfo.Item2 != "") {
                          this.barcode = this.barcode + " " + res.reinfo.Item2;
                      }
                  }

                  this.$refs.xTable.setCurrentRow(this.tableData[0]);
                  this.$nextTick(() => {
                      this.$refs.barcode.select();
                  });
              } else {
                  this.UpPatno = "";
                  this.barcode = res.errmsg;
                  this.$nextTick(() => {
                      this.barcodeFocus();
                  });
              }
          }
      },
      FindDetail() {
          this.loadingDetail = true;
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "querydetail",
                      barcode: this.reqmaster.barcode,
                  },
              })
              .then((res) => {
                  this.tableColumnDetail = res.Cols;
                  this.tableDataDetail = res.Data;
                  this.loadingDetail = false;
              });
      },
      ChangeBarcode() {
          var row = this.$refs.xTable.tableData.filter((item) => item.barcode == this.barcode);
          //验证是否重复扫描
          if (row.length == 0) {
              //判断下方表格是否有数据
              if (this.tableDataAll.length > 0) {
                  //有数据的情况下
                  var row1 = this.$refs.xTable1.tableData.filter((item) => item.barcode == this.barcode);
                  if (row1.length == 0) {
                      //无数据的情况下，有可能扫描了回单号或者是换了病人
                      this.FindAll();
                  } else {
                      //有数据
                      this.submitone(row1[0]);
                  }
              }
              else {
                  //无数据，刷新下方表格
                  this.FindAll();
              }

              this.$nextTick(() => {
                  this.$refs.barcode.select();
              });
          } else {
              this.$refs.xTable.setCurrentRow(row[0]);
              this.$nextTick(() => {
                  this.$refs.barcode.select();
              });
          }
      },
      getAddRptItem(barcode){
          //查找附加报告
          return this.$tool
          .request({
              url: "REQ/REQ1/REQ111",
              method: "post",
              data: {
                  action: "getAddRptItem",
                  barcode: barcode,
              },
          });
      },
      submitreq() {
          var record = this.$refs.xTable.tableData;
          //循环出条码号
          var barcodes = "";
          record.forEach(element => {
              barcodes+= element.barcode + ",";
          });
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "submitall",
                      saveinfo: record,
                      oldinfo: record,
                  },
              })
              .then((res) => {
                  if (res.errcode == 1) {
                      this.patnum = res.patnum;
                      this.barnum = res.barnum;
                      //采样确认成功,查询是否有附加报告
                      this.getAddRptItem(barcodes)
                          .then((res) => {
                              if (!!res.data && res.data.length > 0) {
                                  this.addRptItemVisible = true;
                                  this.AddaRptItemList = res.data;
                              }
                          });
                      this.$message({
                          message: "采样确认成功",
                          type: "success",
                      });
                  } else {
                      this.$message.error("采样确认失败:" + res.errmsg);
                  }
              });
      },
      // 双击采样
      submitone(row) {
          var record = row;
          if (record.req_stat <= 2 || record.req_stat == 8) {
              if (this.tableData.length > 0) {
                  for (let index = 0; index < this.tableData.length; index++) {
                      //新添加时，先把原先的状态设置为0
                      this.tableData[index].isC = 0;
                  }
              }
              if (this.MUSTCLICKEDSAMPLED != "1") {
                  this.$tool
                      .request({
                          url: "REQ/REQ1/REQ111",
                          method: "post",
                          data: {
                              action: "submitone",
                              barcode: record.barcode,
                          },
                      })
                      .then((res) => {
                          if (res.errcode == "1") {
                              this.barcode = this.barcode + " 采样确认成功";

                              this.barnum++;
                              this.patno = res.master.Patno;
                              this.patname = res.master.pat_name;
                              this.patsex = res.master.pat_sex == 1 ? "男" : "女";
                              this.patage = res.master.pat_agestr;

                              row.req_statname = res.master.req_statname;
                              row.req_stat = res.master.req_stat;
                              row.sampled_dt = res.master.sampled_dt;
                              row.sampled_user = res.master.sampled_user;
                              row.sampled_username = res.master.sampled_username;
                              // 此处很重要
                              //this.tableData.push(row);
                              this.tableData.splice(0, 0, row);
                              this.$refs.xTable.insertAt(row, -1);
                              this.$refs.xTable1.remove(row);

                              this.$refs.xTable.setCurrentRow(row);
                              //采样确认成功,查询是否有附加报告
                              this.getAddRptItem(record.barcode)
                                  .then((res) => {
                                      if (!!res.data && res.data.length > 0) {
                                          this.addRptItemVisible = true;
                                          this.AddaRptItemList = res.data;
                                      }
                                  });
                              this.$nextTick(() => {
                                  this.$refs.barcode.select();
                              });
                          } else {
                              this.$message.error("采样确认失败:" + res.errmsg);
                          }
                      });
              }
              else {
                  //移除下方数据，在上方插入数据
                  this.tableData.splice(0, 0, row);
                  this.$refs.xTable.insertAt(row, -1);
                  this.$refs.xTable1.remove(row);

                  this.$refs.xTable.setCurrentRow(row);
                  this.$nextTick(() => {
                      this.$refs.barcode.select();
                  });
              }
          } else {
              this.$confirm(record.barcode + "检验科已接收该标本，不能重复采样", "提示", {
                  showCancelButton: false,
                  confirmButtonText: "确定",
                  type: "warning",
              });
          }
      },
      btnclearlist() {
          this.tableData = [];
          this.tableDataAll = [];
          this.tableDataDetail = [];
          this.barcode = "";
          this.patno = "";
          this.patname = "";
          this.patsex = "";
          this.patage = "";
          this.$refs.barcode.focus();
      },
      Cancel() {
          if (this.reqmaster.barcode) {
              if (this.reqmaster.req_stat == "2") {
                  this.CancelVisible = true;
              } else {
                  this.$message.error("当前申请不是采样状态，不可取消采样!");
              }
          } else {
              this.$message({
                  message: "未选中取消采样的项目!",
              });
          }
      },
      CommitTips() {
          var filter = this.AddaRptItemList.filter((x) => x.val == "" || x.val == null);
          if (filter.length > 0) {
              this.$message.warning("附加报告项目必须全部录入！");
              this.$refs.AddaRptItemTable.setActiveCell(filter[0], "val");
              return;
          }
          var filter1 = this.AddaRptItemList.filter((x) => x.inputlower != "" && x.inputlower != null);
          var filter2 = this.AddaRptItemList.filter((x) => x.inputupper != "" && x.inputupper != null);
          if (filter1.length > 0) filter1 = filter1.filter((x) => x.val != null && x.val != "" && parseFloat(x.val) < parseFloat(x.inputlower));
          if (filter2.length > 0) filter2 = filter2.filter((x) => x.val != null && x.val != "" && parseFloat(x.val) > parseFloat(x.inputupper));
          if (filter1.length > 0) {
              this.$message.warning("附加报告项目[" + filter1[0].rpt_itemname + "]值[" + filter1[0].val + "]低于下限（" + filter1[0].inputlower + "）！");
              this.$refs.AddaRptItemTable.setActiveCell(filter1[0], "val");
              return;
          } else if (filter2.length > 0) {
              this.$message.warning("附加报告项目[" + filter2[0].rpt_itemname + "]值[" + filter2[0].val + "]超出上限（" + filter2[0].inputupper + "）！");
              this.$refs.AddaRptItemTable.setActiveCell(filter2[0], "val");
              return;
          }
          //处理附加报告
          this.handleAddRptItem();
      },
      CancelTips() {
          this.addRptItemVisible = false;
      },
      handleAddRptItem(){
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "handleAddRptItem",
                      addrptitemlist: this.AddaRptItemList,
                  },
              })
              .then((res) => {
                  if (res.flag == "1") {
                      this.$message.success("附加报告保存成功");
                      this.AddaRptItemList = [];
                      this.addRptItemVisible = false;
                      //聚焦到扫描条码空间
                      this.$nextTick(() => {
                          this.$refs.barcode.select();
                      });
                  } else {
                      this.$message.error(res.msg);
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      CancelCommit() {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "cancel",
                      barcode: this.reqmaster.barcode,
                  },
              })
              .then((res) => {
                  if (res.errcode == 1) {
                      this.$message({
                          message: "取消采样成功",
                          type: "success",
                      });
                      this.CancelVisible = false;
                      this.barnum--;
                      let row = this.$refs.xTable.getCurrentRow();
                      let index = this.$refs.xTable.getRowIndex(row);
                      console.log("index", this.tableData[index]);

                      this.$refs.xTable.remove(row);
                      this.tableData.splice(index, 1);
                      if (this.isnotclearsamplelist == "0") {
                          row.sampled_dt = "";
                          row.sampled_user = "";
                          row.sampled_username = "";
                          row.req_stat = row.print_dt == "" ? "0" : "1";
                          row.req_statname = row.print_dt == "" ? "申请" : "打印/执行";
                          this.$refs.xTable1.insertAt(row, -1);
                          this.$refs.xTable1.tableData.sort((a, b) => a.barcode - b.barcode);
                      }
                      this.barcode = "";
                  } else {
                      this.$alert("采样确认失败:" + res.errmsg, "提示");
                  }
              });
      },
      cellDBLClickEvent({ row, rowIndex, column, columnIndex }, event) {
          this.reqmaster = row;
          if (this.$refs.xTable.tableData.filter((item) => item.barcode == row.barcode).length > 0) {
              // 执行取消采样
              this.Cancel();
              this.$nextTick(() => {
                  this.$refs.barcode.focus();
                  this.$refs.xTable1.setCurrentRow(row);
              });
          } else {
              this.barcode = row.barcode;
              // 执行采样
              this.submitone(row);
              this.$nextTick(() => {
                  this.$refs.barcode.select();
                  this.$refs.xTable.setCurrentRow(row);
              });
          }
      },
      cellClassName({ row, column }) {
          if (column.property == "sampled_username" || column.property == "specimen_name" || column.property == "sampled_dt") {
              if (row[column.property] != "") return "sample-tips";
          }
      },
      rowClassName({ row, rowIndex }) {
          if (row.isC == 1 || rowIndex == 0) {
              return "add-row";
          }
      },
      btnRePrint_click() {
          //打印类型 2：只打印条码 3：只打印回单
          if (!this.Options.cx_backrpt_style) {
              this.$alert("未找到回单条码对应样式!", "提示");
              return;
          }
          var row = this.$refs.xTable.getCurrentRow();
          if (row && row.barcode) {
              this.$tool
                  .request({
                      url: "REQ/REQ1/REQ111",
                      method: "post",
                      data: {
                          action: "getbarback",
                          barcode: row.barcode,
                      },
                  })
                  .then((res) => {
                      if (res && !res.hasOwnProperty("errcode")) {
                          this.$pub.printbackbar(this, "", "1", this.Options.cx_backrpt_style, this.Options.backbarmode, this.Options.cx_backrrintername);
                      }
                  });
          } else {
              this.$alert("未选中要打印的回单", "提示");
          }
      },
      querypredt() {
          var rows = this.$refs.xTable.tableFullData;
          var barcode = "";
          for (let i = 0; i < rows.length; i++) {
              barcode += rows[i].barcode + ",";
          }
          if (barcode.length > 0) barcode = barcode.substring(0, barcode.length - 1);
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ111",
                  method: "post",
                  data: {
                      action: "queryprereportdt",
                      barcode: barcode,
                  },
              })
              .then((res) => {
                  if (res && !res.hasOwnProperty("errcode")) {
                      var tempdata = XEUtils.clone(rows, true);
                      for (let i = 0; i < tempdata.length; i++) {
                          var findrow = res.find((item) => item.Item1 == tempdata[i].barcode);
                          if (findrow) tempdata[i].prereport_dt = findrow.Item2;
                      }
                      this.tableDataPre = tempdata;
                      this.PredtVisible = true;
                  }
              });
      },
      designreport() {
          if (!this.Options.cx_backrpt_style) {
              this.$alert("未找到回单条码对应样式!", "提示");
              return;
          }
          this.$pub.printbackbar(this, "", "3", this.Options.cx_backrpt_style, this.Options.backbarmode);
      },
  },
};
</script>
<style scoped>
/deep/.el-button--primary {
  color: black;
}

/deep/.vxe-input--wrapper .vxe-input {
  height: auto;
  width: 200px;
  border-radius: 0px;
}

/deep/.el-button--default.btn-custom-cancel {
  float: right !important;
  margin-left: 10px;
}

/deep/ .sample-tips {
  color: red;
}

.pagetop {
  left: 0;
  right: 0;
  height: 36px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  height: 100%;
  left: 0;
}

.middle-right {
  height: 100%;
  top: 0;
  bottom: 2px;
  right: 0px;
  overflow: auto;
}

table {
  font-size: 12px;
  border-collapse: separate;
  /* border-spacing: 5px; */
}

/deep/.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}

/deep/.el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}

/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner+.el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}

/deep/.add-row {
  font-weight: 1000;
}
</style>
